//
//  AppDelegate.m
//  MyFirstUIDemo
//
//  Created by 愤怒的振振 on 15-5-25.
//  Copyright (c) 2015年 LiuWeiZhen. All rights reserved.
//

#import "AppDelegate.h"
#define kDebugMethod NSLog(@"%@", NSStringFromSelector(_cmd))

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    kDebugMethod;
    // 当应用程序加载完成后就会马上被调用
    
    // 打印当前方法名
    // NSLog(@"%@", NSStringFromSelector(_cmd));
    
    // 打印当前类名+方法名
    // NSLog(@"%s", __func__);
    
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    
    // 新建一个视图
    UIView *greenView = [[UIView alloc] init];
    
    // 给它设置坐标和大小
    greenView.frame = CGRectMake(60, 100, 200, 80);
    greenView.backgroundColor = [UIColor greenColor];
    
    // 把greenView加到window上
    // 我们把greenView作为一个参数(实参)传给了window的一个方法：
    // - (void)addSubview:greenView
    // window会对greenView进行强引用
    // 当window没了的时候，它会把它的子视图greenView干掉
    // 所以这里我们还是遵循黄金法则的，我们alloc了，所以release
    // 不用去管greenView到底什么时候销毁
    [self.window addSubview:greenView];
    [greenView release];
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(20, 30, 40, 40)];
    lable.backgroundColor=[UIColor redColor];
    [greenView addSubview:lable];
    
    
    // 应用程序类
    // UIApplication 单例
    // [UIApplication sharedApplication];
    // [UIApplication sharedApplication].delegate;
    
    self.window.backgroundColor = [UIColor redColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    kDebugMethod;
    // 当应用程序将要进入非活跃状态（non-active）时，被调用
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    kDebugMethod;
    // 真的进入后台时被调用
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    kDebugMethod;
    // 当应用将要进入前台显示的时候被调用
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    kDebugMethod;
    // 当要出现在我们的面前（显示出来，从后台过到前台），变成active状态，被调用
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    kDebugMethod;
    // 程序终结的时候被调用
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)dealloc {
    self.window = nil;
    [super dealloc];
}

@end
